﻿using Client.Processes;
using Client.ViewModels;
using Contracts.Entities;

namespace Client.Commands
{
    public class ReadMoviesByMovieElementCommand : BaseCommand
    {
        private ReadMovies reader;

        public ReadMoviesByMovieElementCommand()
        {
            this.reader = new ReadMovies();
            this.reader.OnCompleted += m =>
            {
                MainViewModel.Default.ActiveWorkspace.MovieItems = m;
                MainViewModel.Default.ActiveWorkspace.IsBusy = false;
            };
        }

        public override bool CanExecute(object parameter)
        {
            return (parameter as MovieElement != null);
        }

        public override void Execute(object parameter)
        {
            var element = parameter as MovieElement;
            var request = string.Empty;

            switch (element.Type)
            {
                case MovieElementType.Actor: request = string.Format("Filme für {0} {1}", "Schauspieler", element); break;
                case MovieElementType.Director: request = string.Format("Filme für {0} {1}", "Regisseur", element); break;
                case MovieElementType.Country: request = string.Format("Filme für {0} {1}", "Land", element); break;
                case MovieElementType.Genre: request = string.Format("Filme für {0} {1}", "Genre", element); break;
                case MovieElementType.Studio: request = string.Format("Filme für {0} {1}", "Studio", element); break;
            }

            MainViewModel.Default.AddMovieListWorkspace(request);
            MainViewModel.Default.ActiveWorkspace.IsBusy = true;
            reader.Process(element);
        }
    }
}
